﻿using System.Text.Json;

namespace TowerCraneMonitorClient.NetClient
{
    /// <summary>
    /// JSON 对象/反序列化
    /// </summary>
    public class Json
    {
        readonly string jsonString;

        public Json(string jsonString)
        {
            this.jsonString = jsonString;
        }

        /// <summary>
        /// json 字符串反序列化为对象
        /// </summary>
        /// <typeparam name="T">反序列化生成的对象类型</typeparam>
        /// <param name="json">json 字符串</param>
        /// <returns>反序列化生成的对象</returns>
        public T ToObject<T>()
        {
            return JsonSerializer.Deserialize<T>(jsonString);
        }

        public override string ToString() => jsonString;
    }
}
